package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.Tactics;
import com.share.device.domain.vo.TacticsVo;
import com.share.device.service.TacticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 策略相关接口
 * 提供策略的增删改查等操作
 */
@RestController
@RequestMapping("/tactics")
@Tag(name = "策略接口")
public class TacticsController extends BaseController {
    @Autowired
    private TacticsService tacticsService;

    /**
     *  获取策略列表
     * @param tactics
     * @return
     */
    @Operation(summary = "获取策略列表")
    @GetMapping("/list")
    public TableDataInfo list(Tactics tactics){
        startPage();
        List<Tactics> tacticsList = tacticsService.selectTacticsList(tactics);
        return getDataTable(tacticsList);
    }
    /**
     * 添加策略
     * @param tactics
     * @return
     */
    @Operation(summary = "添加策略")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Tactics tactics){
        return tacticsService.save(tactics) ? success() : error();
    }
    /**
     * 修改策略
     * @param tactics
     * @return
     */
    @Operation(summary = "修改策略")
    @PutMapping
    public AjaxResult edit(@RequestBody Tactics tactics){
        return tacticsService.updateById(tactics) ? success() : error();
    }
    /**
     * 删除策略
     * @param id
     * @return
     */
    @Operation(summary = "删除策略")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable @Schema(description = "策略ID", required = true) Long id){
        return tacticsService.removeById(id) ? success() : error();
    }
    /**
     * 获取策略详情
     * @param id
     * @return
     */
    @Operation(summary = "获取策略详情")
    @GetMapping("/{id}")
    public AjaxResult detail(@PathVariable @Schema(description = "策略ID", required = true) Long id){
        TacticsVo tacticsVos = tacticsService.getTactics(id);
        return success(tacticsVos);
    }
    /**
     * 获取策略下拉框
     * @return
     */
    @Operation(summary = "获取策略下拉框")
    @GetMapping("/select")
    public AjaxResult select(){
        List<Tactics> tacticsList = tacticsService.list();
        return success(tacticsList);
    }

}
